<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test-Binray</title>
</head>
<body>
<div class="div-b">
    <form onsubmit="return false;">
		<textarea id="responseText" style="width: 1200px; height: 700px;"
                  disabled="disabled" readonly="readonly"></textarea>
        <br> <input type="text" name="message" style="width: 180px"
                    value="讲真,一点毛病都没"> <input type="button" value="发送"
                                              onclick="chat(this.form.message.value)">
        <input type="button" onclick="javascript:document.getElementById('responseText').value=''" value="clear"> <br>
        <br>
        <input type="text" name="nickname" style="width: 50px" value="玉面小飞龙">
        <input type="button" value="修改昵称"
               onclick="updateName(this.form.nickname.value)">
        <br>
        <input type="text" name="avatar" value="https://mdn.mozillademos.org/files/5397/rhino.jpg">
        <input type="button" value="修改头像"
               onclick="updateAvatar(this.form.avatar.value)">
    </form>
</div>

</body>


<script type="text/javascript">
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = "[" + date.getFullYear() + seperator1 + month
            + seperator1 + strDate + " " + date.getHours() + seperator2
            + date.getMinutes() + seperator2 + date.getSeconds() + "."
            + date.getMilliseconds() + "]";
        return currentdate;
    }

    function log(msg) {
        var ta = document.getElementById('responseText');
        ta.value = ta.value + '\n' + getNowFormatDate() + msg;
        ta.scrollTop = ta.scrollHeight;
    }
</script>

<script type="text/javascript" src="msutil.js"></script>
<script type="text/javascript">

    var a = stringToUtf8ByteArray("暗室逢灯");
    var b = utf8ByteArrayToString(a);
    console.log(b);
</script>


<script src="./bson/dist/bson.js"></script>
<script src="./compress.js"></script>
<script src="./lzw.js"></script>

<script>
    function start() {
        var bson = new BSON();
        var Long = BSON.Long;

        var doc = {
            oid: BSON.ObjectID(),
            long: Long.fromNumber(100),
            int: 256,
            date: new Date(),
            string: "js-bson sample",
            array: [0, 1, 1, 3, 1, 1, 3,0,0,0,0,0,0,0,0,0,0,0,0],
            array1: [{x:1,y:1},{x:1,y:1},{x:1,y:1},{x:1,y:1},{x:1,y:1},{x:1,y:1},{x:1,y:1},{x:1,y:1},{x:1,y:1},],
            obj: {
                string: "Object within an object"
            }
        };
        console.log("json: %o", doc);
        let jsonString = JSON.stringify(doc);
        console.log("json.len:"+ jsonString.length);

        // Serialize a document
        var data = bson.serialize(doc, null);
        console.log("data.encode: %o", data);
        console.log("data.encode.len: " + data.length);

        // De serialize it again
        var doc_2 = bson.deserialize(data);
        console.log("doc_2 %o", doc_2);

        console.log("json.len:"+ jsonString.length);
        var s = lzw_compress(jsonString);
        console.log("[INFO] lzw.len "+s.length);

        lzw_test(jsonString);
    }

    start();
</script>

</html>